/*
 * This program is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this 
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 
 * or from the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright 2008 Pentaho Corporation.  All rights reserved.
 *
 * @author Will Gorman (wgorman@pentaho.com)
 */
package org.pentaho.actioneditor.server;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

import org.pentaho.actioneditor.client.ActionEditorService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class ActionEditorServerDebug extends RemoteServiceServlet implements ActionEditorService {

  private static final long serialVersionUID = -7728316051775986114L;
  
  static final String SOLUTION_PATH = "/home/gorman/platform_workspace/tomcat-pci-test/biserver-ce/pentaho-solutions/";
  
  public String getActionSequenceXml(String actionSequence) {
     String filedata = "";
     try {
       File f = new File(SOLUTION_PATH + actionSequence);
       if (!f.exists()) {
         return "File " + actionSequence + " does not exist.";
       }
       
       BufferedReader br = new BufferedReader(new FileReader(SOLUTION_PATH + actionSequence ));
       String line = br.readLine();
       while (line != null) {
         filedata += line + "\n";
         line = br.readLine();
       }
       br.close();
       
     } catch (Exception e) {
       e.printStackTrace();
     }
     return filedata;
  }
  
  public String saveActionSequenceXml(String actionSequence, String xml) {
    try {
      PrintWriter pw = new PrintWriter(new FileWriter(SOLUTION_PATH + actionSequence));
      pw.print(xml);
      pw.close();
    } catch (Exception e) {
      e.printStackTrace();
      return e.getMessage();
    }
    return "Save Successful";
  }
}
